package czh.cocoa.sample;

import czh.cocoa.foundation.NSArray;
import czh.cocoa.foundation.NSObject;
import czh.cocoa.foundation.NSSelector;
import czh.cocoa.foundation.NSSet;
import czh.cocoa.graphics.CGRect;
import czh.cocoa.ui.UIColor;
import czh.cocoa.ui.UIEvent;
import czh.cocoa.ui.UIFont;
import czh.cocoa.ui.UIImage;
import czh.cocoa.ui.UITextAlignment;
import czh.cocoa.ui.UIView;
import czh.cocoa.ui.UIViewController;
import czh.cocoa.ui.impl.UIActionSheet;
import czh.cocoa.ui.impl.UIAlertView;
import czh.cocoa.ui.impl.UIBarButtonItem;
import czh.cocoa.ui.impl.UIButton;
import czh.cocoa.ui.impl.UIControl;
import czh.cocoa.ui.impl.UILabel;
import czh.cocoa.ui.impl.UINavigationBar;
import czh.cocoa.ui.impl.UINavigationItem;
import czh.cocoa.ui.impl.UITabBar;
import czh.cocoa.ui.impl.UITabBarItem;
import czh.cocoa.ui.impl.UIToolbar;

import static czh.cocoa.ui.impl.UIBarButtonItem.*;

public class MyViewController extends UIViewController {
	
	private UINavigationBar mNaviBar;
	
	private int mNumber;
	
	public MyViewController(int number) {
		mNumber = number;
		UIImage image = UIImage.imageNamed(NSTR("tabicon")); 
		setTabBarItem(new UITabBarItem(NSTR("记录"), image, 0));
	}

	protected void viewDidLoad() {
		UIView view = view();
		UILabel label = new UILabel(view.bounds());
		//label.setBackgroundColor(UIColor.orangeColor());
		label.setFont(UIFont.boldSystemFontOfSize(30));
		label.setText(NSTR("" + mNumber)); 
		label.setTextAlignment(UITextAlignment.Center);
		label.setAutoresizingMask(UIView.UIViewAutoresizingFlexibleSize);
		view.addSubview(label);
		
		UIButton button = new UIButton(CGRectMake(0, 0, 100, 50)); 
		button.setCenter(view.bounds().center()); 
		button.setTitleForState(NSTR("Click it"), UIControl.UIControlStateNormal);
		button.setBackgroundImageForState(UIImage.imageNamed(NSTR("btn_normal")), 
				UIControl.UIControlStateNormal);
		button.setAdjustsImageWhenHighlighted(true);
		button.addTargetActionForControlEvents(this, new NSSelector() {
			@Override
			public void perform(NSObject receiver, NSObject params) {
				UIAlertView dialog = new UIAlertView();
				dialog.setTitle(NSTR("Version 4.2"));
				dialog.setMessage(NSTR("That is a tough dicision !"));
				dialog.addButtonWithTitle(NSTR("Yes")); 
				dialog.addButtonWithTitle(NSTR("No"));
				//dialog.addButtonWithTitle(NSTR("Quit"));
				dialog.show();
				
//				UIActionSheet sheet = new UIActionSheet(NSTR("Hello World"), null, NSTR("No"), 
//						NSTR("Yes"), NSTR("Go"));  
//				
//				sheet.setActionSheetStyle(UIActionSheet.UIActionSheetStyleBlackTranslucent); 
//				
//				sheet.showInView(null);
				
			}
		}, UIControl.UIControlEventTouchUpInside);
		
		view.addSubview(button);
	}
	
	public void test() {
		UINavigationItem item = new UINavigationItem(NSTR("QQ"));
		NSSelector action = new NSSelector() {
			@Override
			public void perform(NSObject receiver, NSObject params) {
				mNaviBar.popNavigationItemAnimated(true);
			}
		};
//		item.setRightBarButtonItem(new UIBarButtonItem(NSTR("done"), 
//									UIBarButtonItemStylePlain, this, null));
		UIImage icon = UIImage.imageNamed(NSTR("robot")); 
		item.setRightBarButtonItem(new UIBarButtonItem(icon, 
									UIBarButtonItemStylePlain, this, action));
		mNaviBar.pushNavigationItemAnimated(item, true); 
	}
	
	public void test2() {
		UINavigationItem item = new UINavigationItem(NSTR("群"));  
		mNaviBar.pushNavigationItemAnimated(item, true); 
	}
	
	public void test3() {
		UINavigationItem item = new UINavigationItem(NSTR(""));  
		mNaviBar.pushNavigationItemAnimated(item, true); 
	}
	
	protected void viewWillAppear() {
		NSLog("view will appear !", ""); 
	}
	
	protected void viewDidAppear() {
		NSLog("view did appear !", ""); 
	}
	
	protected void viewWillDisappear() {
		NSLog("view will disappear !", ""); 
	}
	
	protected void viewDidDisappear() {
		NSLog("view did disappear !", ""); 
	}
	
}
